package pl.edu.uj.tcs.blef.protocol;

import pl.edu.uj.tcs.blef.utils.Ace;
import pl.edu.uj.tcs.blef.utils.Bet;
import pl.edu.uj.tcs.blef.utils.Card;
import pl.edu.uj.tcs.blef.utils.Clubs;
import pl.edu.uj.tcs.blef.utils.Color;
import pl.edu.uj.tcs.blef.utils.ColorBet;
import pl.edu.uj.tcs.blef.utils.Diamonds;
import pl.edu.uj.tcs.blef.utils.Four;
import pl.edu.uj.tcs.blef.utils.Full;
import pl.edu.uj.tcs.blef.utils.Hearts;
import pl.edu.uj.tcs.blef.utils.HighCard;
import pl.edu.uj.tcs.blef.utils.Jack;
import pl.edu.uj.tcs.blef.utils.King;
import pl.edu.uj.tcs.blef.utils.Nine;
import pl.edu.uj.tcs.blef.utils.Pair;
import pl.edu.uj.tcs.blef.utils.Queen;
import pl.edu.uj.tcs.blef.utils.RoyalFlush;
import pl.edu.uj.tcs.blef.utils.Spades;
import pl.edu.uj.tcs.blef.utils.StraightFlush;
import pl.edu.uj.tcs.blef.utils.Ten;
import pl.edu.uj.tcs.blef.utils.Three;
import pl.edu.uj.tcs.blef.utils.TwoPairs;

public class BetRequest extends Request {

	private Bet bet;
	
	public BetRequest(String message, RequestHandler handler) {
		super(message, handler);
		fill();
	}

	@Override
	protected void fill() {
		Color color = null; Card first = null; Card second = null;
		if("C".equals(message.split(" ")[2])) color = new Clubs();
		else if("D".equals(message.split(" ")[2])) color = new Diamonds();
		else if("H".equals(message.split(" ")[2])) color = new Hearts();
		else if("S".equals(message.split(" ")[2])) color = new Spades();
		
		if("9".equals(message.split(" ")[2])) first = new Nine(color);
		else if("10".equals(message.split(" ")[2])) first = new Ten(color);
		else if("J".equals(message.split(" ")[2])) first = new Jack(color);
		else if("Q".equals(message.split(" ")[2])) first = new Queen(color);
		else if("K".equals(message.split(" ")[2])) first = new King(color);
		else if("A".equals(message.split(" ")[2])) first = new Ace(color);
		
		if(message.split(" ").length == 4){
			if("9".equals(message.split(" ")[3])) second = new Nine(color);
			else if("10".equals(message.split(" ")[3])) second = new Ten(color);
			else if("J".equals(message.split(" ")[3])) second = new Jack(color);
			else if("Q".equals(message.split(" ")[3])) second = new Queen(color);
			else if("K".equals(message.split(" ")[3])) second = new King(color);
			else if("A".equals(message.split(" ")[3])) second = new Ace(color);
		}
		
		if("ONE".equals(message.split(" ")[1])) bet = new HighCard(first);
		else if("PAIR".equals(message.split(" ")[1])) bet = new Pair(first);
		else if("TWO-PAIRS".equals(message.split(" ")[1])) bet = new TwoPairs(first, second);
		else if("THREE".equals(message.split(" ")[1])) bet = new Three(first);
		else if("FULL".equals(message.split(" ")[1])) bet = new Full(first, second);
		else if("COLOR".equals(message.split(" ")[1])) bet = new ColorBet(color);
		else if("FOUR".equals(message.split(" ")[1])) bet = new Four(first);
		else if("STRAIGHT-FLUSH".equals(message.split(" ")[1])) bet = new StraightFlush(color);
		else if("ROYAL-FLUSH".equals(message.split(" ")[1])) bet = new RoyalFlush(color);
	}
	
	public Bet getBet(){
		return this.bet;
	}

}
